var _PORTAL_PATH = 'http://bongdaplus.vn/';
var _STATIC_PATH = 'http://static.bongdaplus.vn/';
var _MEDIA_PATH = 'http://media.bongdaplus.vn/';

//GetElementById
function $E(e) {
    if (!e) { return (document.body || document.getElementsByTagName('body')[0]) || 0; }
    return (e.tagName ? e : document.getElementById(e)) || 0;
}
//GetElement(s)ByTagName
function $T(e, t, i) {
    e = $E(e);
    if (!e) return [];

    e = e.getElementsByTagName(t) || [];
    if (i == 0 || (i > 0 && i < e.length)) { return e[i] || 0; }
    return e;
}
//GetElement(s)ByClassName
function $C(e, c, t, i) {
    e = $E(e);
    if (!e) return [];

    var a = [];
    if (e.getElementsByClassName) {
        e = e.getElementsByClassName(c);

        t = t ? t.toString().toLowerCase() : '';
        for (var j = 0; j < e.length; j++) {
            if (!t || e[j].tagName.toLowerCase() == t) { a.push(e[j]); }
        }
    }
    else {
        e = e.getElementsByTagName(t || '*');
        for (var j = 0; j < e.length; j++) {
            if ((' '+e[j].className+' ').indexOf(' '+c+' ') > -1) { a.push(e[j]); }
        }
    }

    if (!a.length) return 0;
    if (i == 0 || (i > 0 && i < a.length)) { return a[i] || 0; }
    return a;
}
//CreateElementByTagNameFromParentElement
function $N(e, t, a, s) {
    var n = document.createElement(t);
    e = $E(e) || document; e.appendChild(n);
    if (e) { n.id = e; }
    if (a) { for (var i in a) { n[i] = a[i]; } }
    if (s) { for (var i in s) { n.style[i] = s[i]; } }
    return n;
}
//ShowOrHideElement
function $SH(e, s) {
    e = $E(e);
    if (!e) return;
    if (s == null || s == 'undefined') { e.style.display = (e.style.display == 'none') ? '' : 'none'; }
    else { e.style.display = (typeof (s) == 'string') ? s : (!s ? 'none' : 'block'); }
}
//FormatTwoCharNumber(00)
function $FN(n) { n = '00' + n.toString(); return n.substring(n.length - 2); }
//CreateAJAXRequest
function $X() {
    try { return new XMLHttpRequest(); }
    catch (e) { }

    try { return new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) { }

    try { return new ActiveXObject("Msxml.XMLHTTP"); }
    catch (e) { }

    return 0;
}
//CallAJAXRequestFromPath
function $XR(u, f, r) {
    if (!f || !u) return;
    var x = $X();
    if (!x) { if (r) { r(); } return; }
    x.onreadystatechange = function () { if (x.readyState == 4 && x.status == 200) { if (f) { f(x); } x = null; } };
    x.open("GET", u, true);
    x.send();
}
//CallSyncronousAJAXRequestFromPath
function $XS(u, f) {
    if (!f || !u) return;
    var x = $XC();
    if (!x) return;
    x.open("GET", u, false);
    x.send();
    if (f) { f(x); }
    x = null;
}

var Handlers = {
    _LOAD: 0, _CLICK: 1, _SCROLL: 2, _RESIZE: 3, _FOCUS: 4, _BLUR: 5, __exec: [[], [], [], [], [], []],
    call: function (e) {
        var h = Handlers.__exec[e];
        if (h) {
            for (var i = 0; i < h.length; i++) {
                try { h[i](); } catch (x) { }
            }
        }
    },
    add: function (e, f) {
        if (typeof (f) != 'function' && f.toString().indexOf('function') < 0) return;
        var r = Handlers.__exec[e];
        if (!r) { r = Handlers.__exec[e] = []; }
        r.push(f);
    }
};
var Capcha = {
    key: 0,
    chars: 'ABCDEFGHMNLBJKGPVXYZABCDE',
    get: function (l) {
        var s = '', d = new Date();
        if (Capcha.key < Capcha.chars.length - 3) { Capcha.key += 3; }
        else { Capcha.key = d.getHours(); }

        var u = '';
        while (s.length < l) {
            Capcha.key = parseInt(Math.random(Capcha.key) * Capcha.chars.length) + 1;
            if (Capcha.key >= Capcha.chars.length) { Capcha.key = parseInt(d.getMilliseconds() / 25); }

            switch (Capcha.key % 4) {
                case 1: u = Capcha.chars[Capcha.key]; break;
                case 2: u = parseInt(Math.random(d.getSeconds() + d.getHours()) * 100, 0).toString(); break;
                case 3: u = Capcha.chars[(Capcha.key > 3 ? Capcha.key - 3 : Capcha.key + 3)]; break;
                default: u = parseInt(d.getMilliseconds() / 100).toString(); break;
            }

            if (!u) continue;
            s += u;
        }
        return s;
    },
    show: function (e, l) {
        var t = $E(e);
        if (t) { t.value = Capcha.get(l || 4); }
    }
};
var Util = {
    winwid: function () { return Math.max(window.innerWidth, document.documentElement.clientWidth, document.body.clientWidth, 0); },
    winhei: function () { return Math.max(window.innerHeight, document.documentElement.clientHeight, document.body.clientHeight, 0); },
    scrtop: function () { return Math.max(window.pageYOffset, document.documentElement.scrollTop, document.body.scrollTop, 0); },
    scrlft: function () { return Math.max(window.pageXOffset, document.documentElement.scrollLeft, document.body.scrollLeft, 0); },
    conthei: function () {
        var a = $E('frameBoundr');
        if (a) { return a.offsetHeight; }
        return Util.winhei();
    },
    frmhei: function (e) {
        e = $E(e);
        if (!e) return;
        e = (e.contentWindow || e.contentDocument);
        if (e.Util) { return e.Util.conthei(); }
        if (!e.document) { e = e.getParentNode(); }
        else { e = e.document; }

        if (e.getElementById) {
            var f = e.getElementById('frameBoundr');
            if (f) { return f.offsetHeight; }
        }

        var b = e.body, h = e.documentElement;
        return Math.max(b.offsetHeight, b.scrollHeight, h.clientHeight, h.offsetHeight, h.scrollHeight);
    },
    fixFrameHei: function (e) {
        e = $E(e) || this;
        var a = Util.frmhei(e);
        if (a) { e.style.height = a + 'px'; }
    },
    showToolbar: function () {
        var t = $E('toolHome');
        if (!t) return;
        var st = Util.scrtop();
        if (t) { if (st && st > 100) { t.className = 'over'; } else { t.className = ''; } }
        $SH('toolSrch', !!(st && st > 100));
    },
    bindElem: function () {
        for (var p in window.BDP) {
            var a = window.BDP[p], b = $E(p);
            if (a && b) { a(b); }
        }
    }
};

var Media = {
    _AUTO_NUMB: 0,
    _MDA_STREAM: 'http://static.bongdaplus.vn:8080/',
    _JWS_PROPS: { wmode: 'transparent', height: 270, width: '100%', stretching: 'fill', autostart: false, bufferlength: '1', 'controlbar.position': 'over', skin: _STATIC_PATH + 'jwp/skin/bdpvdo/bdpvdo.xml', image: '', file: '', provider: 'rtmp', streamer: 'rtmp://static.bongdaplus.vn:1935/vod/',
        modes: [{ type: 'flash', src: _STATIC_PATH + 'jwp/player.swf' }, { type: 'html5', config: { 'file': '', 'provider': 'video'} }, { type: 'download', config: { 'file': '', 'provider': 'video'}}]
    },
    _JWV_PROPS: { flashplayer: _STATIC_PATH + 'jwp/player.swf', height: 270, width: '480', stretching: 'uniform', autostart: false, 'controlbar.position': 'over', skin: _STATIC_PATH + 'jwp/skin/bdpvdo/bdpvdo.xml', image: '', file: '' },
    _JWA_PROPS: { flashplayer: _STATIC_PATH + 'jwp/player.swf', height: 270, width: '480', stretching: 'uniform', autostart: false, 'controlbar.position': 'over', skin: _STATIC_PATH + 'jwp/skin/bdprdo/bdprdo.xml', image: '', file: '' },
    _JWR_PROPS: { flashplayer: _STATIC_PATH + 'jwp/player.swf', height: 28, width: '100%', icons: false, autostart: false, 'controlbar.position': 'bottom', skin: _STATIC_PATH + 'jwp/skin/bdprdo/bdprdo.xml', file: '' },
    playstm: function (e, p, t, a) { if (!p || !jwplayer) { $SH(e, 0); return; } this._JWS_PROPS.file = p; this._JWS_PROPS.image = t || ''; this._JWS_PROPS.modes[1].config.file = this._MDA_STREAM + p; this._JWS_PROPS.modes[2].config.file = this._MDA_STREAM + p; this._JWS_PROPS.autostart = (a || false); jwplayer(e).setup(this._JWS_PROPS); },
    playvid: function (e, p, t, a) { if (!p || !jwplayer) { $SH(e, 0); return; } this._JWV_PROPS.file = (Detector&&Detector.isMobOrTab() ? p.replace('.flv', '.mp4').replace('.3gp', '.mp4') : p); this._JWV_PROPS.image = t || ''; this._JWV_PROPS.autostart = (a || false); jwplayer(e).setup(this._JWV_PROPS); },
    playaud: function (e, p, a) { if (!p || !jwplayer) { $SH(e, 0); return; } this._JWA_PROPS.file = p; this._JWA_PROPS.autostart = (a || false); jwplayer(e).setup(this._JWA_PROPS); },
    playrdo: function (e, p) { if (!p || !jwplayer) { $SH(e, 0); return; } this._JWR_PROPS.file = p; jwplayer(e).setup(this._JWR_PROPS); }
};

function RepTxt(e) {
    if (!e.title) { e.title = e.value; e.value = '';e.className += ' actv'; }
    if (!e.onblur) { e.onblur = function () { if (!e.value) { e.value = e.title; e.title = ''; e.className = e.className.replace(' actv', ''); } }; }
}

window.BDP = {};
//SetAllPageLoadProperties&StartScript
window.onload = function () {
    Util.bindElem();
    Util.showToolbar();

    Handlers.call(Handlers._LOAD);
    Handlers.add(Handlers._RESIZE, Util.showToolbar);
    Handlers.add(Handlers._SCROLL, Util.showToolbar);

    window.onresize = function () { Handlers.call(Handlers._RESIZE); };
    window.onscroll = function () { Handlers.call(Handlers._SCROLL); };
    window.onclick = function () { Handlers.call(Handlers._CLICK); };
    window.onfocus = function () { Handlers.call(Handlers._FOCUS); };
    window.onblur = function () { Handlers.call(Handlers._BLUR); };
};

function expand_AdsFrame() {
    var frmTVC = $E("frmAds_iTVC");
    if (!frmTVC) return;

    frmTVC.style.width = "600px";
    frmTVC.style.marginLeft = "-300px";
    frmTVC.style.position = "absolute";
    frmTVC.style.zIndex = "1000";
}
function collapse_AdsFrame() {
    var frmTVC = $E("frmAds_iTVC");
    if (!frmTVC) return;

    frmTVC.style.width = "300px";
    frmTVC.style.marginLeft = "0";
}
window.BDP.AdFloatr = function (e) {
    e.repos = function () {
        var a = e.offsetWidth;
        if (a < 1160) return;

        a = (a - 1330) / 2;
        var b = $C(e, 'adft_lft', 'div');
        for (var i = 0; b && i < b.length; i++) {
            b[i].style.left = a + 'px';
        }
        b = $C(e, 'adft_rgt', 'div');
        for (var i = 0; b && i < b.length; i++) {
            b[i].style.right = a + 'px';
        }
    };

    e.repos();
    Handlers.add(Handlers._RESIZE, e.repos);
}